<template>
  <div class="tech-map-page">
    <div class="page-header">
      <div class="header-content">
        <h1>技术图谱</h1>
        <p class="subtitle">探索现代技术栈，发现最佳实践</p>
      </div>
      <div class="search-box">
        <input 
          v-model="searchQuery" 
          type="text" 
          placeholder="搜索技术..."
          class="search-input"
        >
        <i class="icon-search"></i>
      </div>
    </div>

    <div class="tech-content">
      <div class="tech-categories">
        <div 
          v-for="category in categories" 
          :key="category.id"
          class="category-card"
        >
          <div class="category-header">
            <h2>{{ category.name }}</h2>
            <span class="tech-count">{{ category.technologies.length }} 项技术</span>
          </div>
          
          <div class="tech-list">
            <div 
              v-for="tech in filteredTechs(category.technologies)" 
              :key="tech.id"
              class="tech-item"
              @click="navigateToTech(tech)"
            >
              <div class="tech-icon">
                <img :src="tech.icon" :alt="tech.name">
              </div>
              <div class="tech-info">
                <h3>{{ tech.name }}</h3>
                <p class="tech-description">{{ tech.description }}</p>
                <div class="tech-tags">
                  <span 
                    v-for="tag in tech.tags" 
                    :key="tag"
                    class="tag"
                  >
                    {{ tag }}
                  </span>
                </div>
                <div class="tech-meta">
                  <span class="meta-item">
                    <i class="icon-star"></i>
                    {{ tech.stars }}
                  </span>
                  <span class="meta-item">
                    <i class="icon-users"></i>
                    {{ tech.users }}
                  </span>
                  <span class="meta-item" :class="tech.trend">
                    <i class="icon-trend"></i>
                    {{ tech.trend }}
                  </span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { categories } from '~/data/tech-data'

const searchQuery = ref('')

const filteredTechs = (technologies) => {
  if (!searchQuery.value) return technologies
  
  const query = searchQuery.value.toLowerCase()
  return technologies.filter(tech => 
    tech.name.toLowerCase().includes(query) ||
    tech.description.toLowerCase().includes(query) ||
    tech.tags.some(tag => tag.toLowerCase().includes(query))
  )
}

const navigateToTech = (tech) => {
  navigateTo(`/tech-map/${tech.id}`)
}
</script>

<style scoped>
.tech-map-page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 24px;
}

.page-header {
  margin-bottom: 48px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 32px;
}

.header-content {
  flex: 1;
}

.header-content h1 {
  margin: 0;
  font-size: 36px;
  font-weight: 700;
  color: var(--text-primary);
}

.subtitle {
  margin: 8px 0 0;
  font-size: 16px;
  color: var(--text-secondary);
}

.search-box {
  position: relative;
  width: 320px;
}

.search-input {
  width: 100%;
  padding: 12px 16px;
  padding-right: 40px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-size: 16px;
  transition: all 0.3s;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(var(--primary-color-rgb), 0.1);
}

.search-box i {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
}

.tech-content {
  display: grid;
  gap: 32px;
}

.tech-categories {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 24px;
}

.category-card {
  background-color: #ffffff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: transform 0.3s, box-shadow 0.3s;
}

.category-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.category-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.tech-count {
  font-size: 14px;
  color: var(--text-secondary);
  background-color: #f8f9fa;
  padding: 4px 8px;
  border-radius: 4px;
}

.tech-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tech-item {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 16px;
  background-color: #f8f9fa;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
}

.tech-item:hover {
  transform: translateX(4px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.tech-icon {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  background-color: #ffffff;
  border-radius: 8px;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tech-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.tech-info {
  flex: 1;
  min-width: 0;
}

.tech-info h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.tech-description {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.tech-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.tag {
  padding: 4px 8px;
  background-color: var(--bg-secondary);
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.tech-meta {
  display: flex;
  gap: 16px;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.meta-item i {
  font-size: 14px;
}

.meta-item.上升 {
  color: #10b981;
}

.meta-item.稳定 {
  color: #6366f1;
}

.meta-item.下降 {
  color: #ef4444;
}

@media (max-width: 1024px) {
  .tech-categories {
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  }
}

@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    width: 100%;
  }

  .tech-categories {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .tech-map-page {
    padding: 24px 16px;
  }

  .header-content h1 {
    font-size: 28px;
  }

  .tech-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .tech-icon {
    margin-bottom: 16px;
  }
}
</style> 